package com.flower.subject.application.handler;


import com.flower.subject.application.dto.MessageDTO;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-09-23 17:34
 */
@Controller
public class MessageHandler {

    @MessageMapping("/send")
    @SendTo("/topic/messages")
    public MessageDTO sendMessage(MessageDTO message) {
        return new MessageDTO("Hello, WebSocket!", "System");
    }


    @MessageMapping("/receive")
    @SendTo("/topic/messages")
    public MessageDTO receiveMessage(MessageDTO message) {
        return new MessageDTO("Received your message: " + message.getContent(), "System");
    }

}
